package com.runen.infinitemovement.adapter;

import android.content.Context;
import android.text.Html;
import android.text.TextUtils;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.module.LoadMoreModule;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.runen.infinitemovement.R;
import com.runen.infinitemovement.model.api.UserAPI;
import com.runen.infinitemovement.model.entity.ReplyCommentListBean;

/**
 * Create by LiaoDuanHong
 * Create on 2020/09/03 11:24
 */
public class CommentMessageAdapter extends BaseQuickAdapter<ReplyCommentListBean, BaseViewHolder> implements LoadMoreModule {
    private Context context;

    public OnSecondItemClick getOnSecondItemClick() {
        return onSecondItemClick;
    }

    public void setOnSecondItemClick(OnSecondItemClick onSecondItemClick) {
        this.onSecondItemClick = onSecondItemClick;
    }

    private OnSecondItemClick onSecondItemClick;

    public CommentMessageAdapter(Context context) {
        super(R.layout.item_comment_message);
        this.context = context;
    }

    @Override
    protected void convert(BaseViewHolder helper, ReplyCommentListBean item) {
        LinearLayout ll_comment_reply = helper.getView(R.id.ll_comment_reply);
        TextView tv_other_name = helper.getView(R.id.tv_other_name);
        TextView tv_see_more = helper.getView(R.id.tv_see_more);
        if (item.reviewerName.contains("CHECK_ALL")) {
            tv_see_more.setVisibility(View.VISIBLE);
            tv_other_name.setVisibility(View.GONE);
            tv_see_more.setText(item.content);
        } else {
            tv_see_more.setVisibility(View.GONE);
            tv_other_name.setVisibility(View.VISIBLE);
            String user_content_info;
            if (!TextUtils.isEmpty(item.replyUserName) || !TextUtils.isEmpty(item.reviewerName)) {
                if (!item.replyUserName.equals(item.reviewerName)) {
                    user_content_info = "<font color='#333333'>" + item.reviewerName + "</font>" + "回复" + "<font color='#333333'>" + item.replyUserName + "</font>" + "：";
                } else {
                    user_content_info = "<font color='#333333'>" + item.reviewerName + "</font>" + "：";
                }
                String str = "%s%s";
                tv_other_name.setText(Html.fromHtml(String.format(str, user_content_info, item.content)));
            }
        }

        ll_comment_reply.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (null != onSecondItemClick) {
                    onSecondItemClick.onItemClick(item);
                }
            }
        });
        tv_see_more.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (null != onSecondItemClick) {
                    onSecondItemClick.onMoreClick();
                }
            }
        });
    }

    public interface OnSecondItemClick {
        /**
         * 二级回复
         *
         * @param secondItem
         */
        void onItemClick(ReplyCommentListBean secondItem);

        /**
         * 查看更多评论
         */
        void onMoreClick();
    }
}
